package 继承.多态练习;

public class Person{
    private String name;
    private int age;

    public Person() {
    }
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

    //饲养动物
//    public void keepPet(Dog dog,String something){
//        System.out.println(age+"岁的"+name+"养了一只"+ dog.getAge()+"岁"+dog.getColor()+"色的狗");
//    }



    //多态类型！！！！------------------------------------------------
    public void keepPet(Animal animal,String something){
       if (animal instanceof Dog dog){
           System.out.println(age+"岁的"+name+"养了一只"+ dog.getAge()+"岁"+dog.getColor()+"色的狗");
           dog.eat(something);
       }else if (animal instanceof Cat cat){
           System.out.println(age+"岁的"+name+"养了一只"+ cat.getAge()+"岁"+cat.getColor()+"色的猫");
           cat.eat(something);
       }else {
           System.out.println("没有这种动物");
       }
    }
}
